﻿#include "ssReadCsv.h"


namespace StarSeeker
{

ssReadCsv::ssReadCsv()
{
}

ssReadCsv::~ssReadCsv()
{
}

bool ssReadCsv::LoadCsvFromFile(const char* path)
{
	m_read.SetPath(path);
	if (!m_read.OpenFile())
	{
		return false;
	}
	u32 count = 0;
	while (m_read.GetLine(0,0))
	{
		if (count++ > 2)
		{
			ssString line = m_read.GetBuffer().Buf();
			if (line.Length())
			{
				if (line[line.Length() - 1] == '\r')
					line[line.Length() - 1] = 0;

				ssString::StrElements_t out;
				line.StringSplit('\t', out);
				if (out.Count())
				{
					m_tab.PushBack(out);
				}
			}
		}
	}
	m_read.CloseFile();
	return true;
}

StarSeeker::ulint ssReadCsv::LineCount()
{
	return m_tab.Count();
}

ssString::StrElements_t* ssReadCsv::GetLine(u32 index)
{
	if (index < m_tab.Count())
	{
		return &m_tab[index];
	}
	return 0;
}

}
